<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="68px">
      <el-form-item label="进件ID" prop="queryId">
        <el-input
          v-model="queryParams.queryId"
          placeholder="请输入进件ID"
          clearable
          @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="查询账号" prop="userId" v-has-role="['admin']">
        <el-select v-model="queryParams.userId" placeholder="请选择" @keyup.enter.native="handleQuery">
          <el-option
            v-for="item in userOptions"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="查询项目" prop="productId">
        <el-select v-model="queryParams.productId" placeholder="请选择">
          <el-option
            v-for="item in options"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="chargeList">
      <el-table-column label="单号" align="center" prop="id"/>
      <el-table-column label="进件ID" align="center" prop="queryId"/>
      <el-table-column label="查询账号" align="center" prop="userName"/>
      <el-table-column label="查询项目" align="center" prop="productName"/>
      <el-table-column label="扣前余额" align="center" prop="beforeBalance"/>
      <el-table-column label="扣费额" align="center" prop="costNum"/>
      <el-table-column label="扣后余额" align="center" prop="afterBalance"/>
      <el-table-column label="创建时间" align="center" prop="createTime"/>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button v-if="scope.row.sort=='1'" type="text" @click="openReport(scope.row)">查看报告</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"/>
    <el-dialog :title="title" :visible.sync="open" width="90%" @close="closeReport()" :close-on-click-modal="false">
      <el-descriptions direction="vertical" :column="4" border size="mini">
        <el-descriptions-item label="姓名">{{ keyInfo.name }}</el-descriptions-item>
        <el-descriptions-item label="身份证">{{ keyInfo.cardNo }}</el-descriptions-item>
        <el-descriptions-item label="手机号">{{ keyInfo.tel }}</el-descriptions-item>
        <el-descriptions-item label="查询时间">{{ queryTime }}</el-descriptions-item>
      </el-descriptions>
      <jcxx v-if="code == 'jcxx'" ref="jcxx"
            :queryData="{
                    queryId: item.queryId,
                    productId: item.productId
             }"
            :head="false"></jcxx>
      <zjrl v-if="code == 'zjrl'" ref="zjrl"
            :queryId="item.queryId"
            :keyInfo="keyInfo"
            :head="false"></zjrl>
      <syshc v-if="code == 'syshc'" ref="syshc"
             :queryData="{
                    queryId: item.queryId,
                    productId: item.productId
             }"
             :head="false"></syshc>
      <qjld v-if="code == 'qjld'" ref="qjld"
            :queryData="{
                    queryId: item.queryId,
                    productId: item.productId
                   }"
            :head="false"></qjld>
      <dttz v-if="code == 'dttz'" ref="dttz"
            :queryData="{
                    queryId: item.queryId,
                    productId: item.productId
                   }"
            :head="false"></dttz>
      <blxw v-if="code == 'blxw'" ref="blxw"
            :queryData="{
                    queryId: item.queryId,
                    productId: item.productId
                   }"
            :head="false"></blxw>
      <sqyx v-if="code == 'sqyx'" ref="sqyx"
            :queryData="{
                    queryId: item.queryId,
                    productId: item.productId
                   }"
            :head="false"></sqyx>
      <graj v-if="code == 'graj'" ref="graj"
            :queryData="{
                    queryId: item.queryId,
                    productId: item.productId
            }"
            :head="false"></graj>
      <tza v-if="code == 'tza'" ref="tza"
           :queryData="{
                    queryId: item.queryId,
                    productId: item.productId
            }"
           :head="false"></tza>
      <jxzs v-if="code == 'jxzs'" ref="jxzs"
            :queryData="{
                    queryId: item.queryId,
                    productId: item.productId
                   }"
            :head="false"></jxzs>
      <hy v-if="code == 'hy'" ref="hy"
          :queryData="{
                    queryId: item.queryId,
                    productId: item.productId
                   }"
          name=""
          cardNo=""
          :head="false"></hy>
      <grbdc v-if="code == 'grbdc'" ref="grbdc"
             :queryId=item.queryId
             :head="false"></grbdc>
      <qwdbg v-if="code == 'qwdbg'" ref="qwdbg"
             :queryData="{
               queryId: item.queryId,
               productId: item.productId
             }"
             :info="keyInfo"
             :head="false"></qwdbg>
      <rzbd v-if="code == 'rzbd'" ref="qwdbg"
            :queryData="{
               queryId: item.queryId,
               productId: item.productId
             }"
            :head="false"></rzbd>
    </el-dialog>
  </div>
</template>

<script>
  import jcxx from "@/views/components/jcxx.vue";
  import zjrl from "@/views/components/zjrl.vue";
  import syshc from "@/views/components/syshc.vue";
  import yys from "@/views/components/yys.vue";
  import qjld from "@/views/components/qjld.vue";
  import dttz from "@/views/components/dttz.vue";
  import blxw from "@/views/components/blxw.vue";
  import tza from "@/views/components/tza.vue";
  import hy from "@/views/components/hy.vue";
  import grbdc from "@/views/components/grbdc.vue";
  import sqyx from "@/views/components/sqyx.vue";
  import rzbd from "@/views/components/rzbd.vue";
  import graj from "@/views/components/graj.vue";
  import jxzs from "@/views/components/jxzs.vue";
  import qwdbg from "@/views/components/qwdbg.vue";

  import {subList} from "@/api/system/charge";
  import {userName} from "@/api/system/user";
  import {productName} from "@/api/system/product";
  import {getQuery} from "@/api/system/query";

  export default {
    components: {
      jcxx,
      zjrl,
      syshc,
      yys,
      qjld,
      dttz,
      blxw,
      tza,
      hy,
      grbdc,
      sqyx,
      rzbd,
      graj,
      jxzs,
      qwdbg
    },
    name: "Charge",
    data() {
      return {
        item: undefined,
        title: '',
        open: false,
        code: '',
        queryTime: undefined,
        userOptions: [],
        options: [],
        // 遮罩层
        loading: true,
        // 总条数
        total: 0,
        // 收费记录表格数据
        chargeList: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 20,
          queryId: undefined,
          userId: undefined,
          productId: undefined
        },
        keyInfo: {
          name: undefined,
          cardNo: undefined,
          tel: undefined
        },
      };
    },
    created() {
      this.getList();
      userName().then(response => {
        this.userOptions = response.data;
      });
      productName().then(response => {
        this.options = response.data;
      });
    },
    methods: {
      /** 查询收费记录列表 */
      getList() {
        this.loading = true;
        if (!this.$auth.hasRole("admin")) {
          this.queryParams.userId = this.$store.state.user.id
        }
        subList(this.queryParams).then(response => {
          this.chargeList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      openReport(item) {
        this.item = item
        this.queryTime = item.createTime
        this.title = item.productName
        this.code = item.code
        getQuery(item.queryId).then(response => {
          if (response.code == 200) {
            let data = response.data
            this.keyInfo = data
            this.open = true
          }
        })
      },
      closeReport() {
        this.code = ''
        this.open = false
      }
    }
  };
</script>
